package edu.cs.usask.ca.silver.plugin.rcp.handlers.ui;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;

import edu.cs.usask.ca.silver.businesslogic.ids.BaseId;
import edu.cs.usask.ca.silver.plugin.rcp.components.SilverTreeObject;
import edu.cs.usask.ca.silver.plugin.rcp.views.projectviewer.ProjectViewI;

public class ShowSelectedHandler extends AbstractHandler implements
		ISelectionListener {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		ProjectViewI view = (ProjectViewI) HandlerUtil
				.getActiveWorkbenchWindow(event)
				.getActivePage()
				.findView(
						event.getParameter("edu.cs.usask.ca.silver.plugin.rcp.popup.showSelected.viewID"));

		SilverTreeObject selection = view.getTreeSelectionAsSilverTreeObject();
		BaseId result = null;
		if (selection != null)
			result = selection.getSilverObjectId();

		return result;
	}

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
		setEnabled(false);
		// TODO Auto-generated method stub

	}

}
